# v2-1-baseのモデル
import torch

from diffusers import StableDiffusionImg2ImgPipeline, UniPCMultistepScheduler
from PIL import Image
torch.backends.cuda.matmul.allow_tf32 = True
init_img = Image.open("../data/upscaled_image2023_07_19_21_42_41.png")
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("C:/Users/Administrator/Downloads/revAnimated_v122",
                                                      safety_checker=None,torch_dtype=torch.float16 )
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

import os
os.environ['CURL_CA_BUNDLE'] = ''

pipe = pipe.to("cuda")
pipe.enable_xformers_memory_efficient_attention()
# pipe.enable_attention_slicing()
# pipe.enable_vae_slicing()
# pipe.enable_attention_slicing(1)

# pipe.enable_sequential_cpu_offload()
# pipe.enable_attention_slicing("max")
pipe.vae.enable_tiling()
# 设置tile的参数
# プロンプト
# prompt = "the style of Gogh"
# prompt = "a beautiful landscape photo"
prompt = "((best quality)), ((masterpiece)), (detailed), woman with green hair, holding a sword, (Artgerm inspired:1.2), (pixiv contest winner:1.1), (octopus goddess:1.3), (Berserk art style:1.2), close-up portrait, goddess skull, (Senna from League of Legends:1.1), (Tatsumaki with green curly hair:1.2), card game illustration, thick brush, HD anime wallpaper, (Akali from League of Legends:1.1), 8k resolution"
negative_prompt = "3d, cartoon, anime, sketches, (worst quality, bad quality, child, cropped:1.4) ((monochrome)), ((grayscale)),  (bad-hands-5:1.0), (badhandv4:1.0), (easynegative:0.8),  (bad-artist-anime:0.8), (bad-artist:0.8), (bad_prompt:0.8), (bad-picture-chill-75v:0.8), (bad_prompt_version2:0.8),  (bad_quality:0.8)"  # パイプラインの実行
# generator = torch.Generator().manual_seed(0)
# with torch.autocast("cuda"):
#     image = pipe(prompt, image=init_img, guidance_scale=7.5, strength=0.75, generator=generator).images[0]
image = pipe(prompt, image=init_img, guidance_scale=7.5, strength=0.5, num_inference_steps=10,
             negative_prompt=negative_prompt).images[0]
# 设置image的大小
import datetime

now = datetime.datetime.now()
# 转换为指定的格式:
otherStyleTime = now.strftime("%Y_%m_%d_%H_%M_%S")
# 変換した画像の保存
image.save("../data/img2img_tile_" + otherStyleTime + ".png")
